
import AbsControler from '../abscontroler.js'
import LXCOM from '../../common/common.js'
import GlobalConst from '../../common/globalConst.js'
var globalconsts = GlobalConst.GlobalConst;

import LXCOORD from '../../common/struct/coord.js'

import {LGXEnums}  from '../../common/sysenum.js';

import utilfuncs from '../../common/tools/utilfuncs.js';
var funcs = utilfuncs.UtilFuncs;
import { CommonSvc } from '../../service/commonsvc.js';

import multimodifysvc from '../../service/multimodifysvc.js';
var multiTransSvc = multimodifysvc.CMultiModifySvc;

class MultiModifyControler extends AbsControler.AbsControler {
    constructor(parent, datamanger, mulSelSvc) {
        super(datamanger);
        this.parentControler = parent;
        this.m_inModifing = false;
        this.m_bIsInMultiProcess = false;
        this.m_pRectSelectService = mulSelSvc;
        this.m_modifyStartPt = new LXCOM.LGXPoint();
        this.m_tSelRect = new LXCOM.LGXRect(0, 0, 0, 0);
    }

    act2Mouse(mosEvnt, worldPos) {
        if (mosEvnt.type == LGXEnums.LGXMouseMode.LMouseDown) {
            this.ActLeftMouseDown(worldPos);
        }
        else if (mosEvnt.type == LGXEnums.LGXMouseMode.LMouseUp) {
            this.ActLeftMouseUp(worldPos);
        }
        else if (mosEvnt.type == LGXEnums.LGXMouseMode.RMouseUp) {
            console.log("rmouse up");
        }
        else if (mosEvnt.type == LGXEnums.LGXMouseMode.LMouseDbClick) {
            this.actionMouseDoubleClicked(worldPos);
        }
        else if (mosEvnt.type == LGXEnums.LGXMouseMode.mouseMove) {
            this.ActMouseMove(worldPos, mosEvnt.type)
        }
        else if (mosEvnt.type == LGXEnums.LGXMouseMode.mouseDrag) {
            this.actLeftMouseDrag(worldPos);
        }
    }

    actLeftMouseDrag(point) {
        var tValidPoint = new LXCOM.LGXPoint();
        tValidPoint.clone(point);
        this.m_pRectSelectService.actMouseMove(tValidPoint);
        this.actToMultiModify(LGXEnums.LGXMouseMode.mouseMove, tValidPoint, 1);
        return 0;
    }

    ActLeftMouseDown(point) {
        var tValidPoint = new LXCOM.LGXPoint();
        tValidPoint.clone(point);
        var pMulSelRect = this.dataManger.getMulSelRectGraph();
        if (pMulSelRect && pMulSelRect.getUseful() == 1) {
            let scaling = this.dataManger.getScaling();
            let mapscale = this.dataManger.getMapScale();
            var selKind = pMulSelRect.calculateSelKind(point, scaling, mapscale, false);
            if (selKind == 0) {
                //批量过程中，如果鼠标左键按下在框选区域外，则结束批量模式
                this.finishMultiMode();
                return 1;
            }
        }

        var needStartNewSelRegion = false;
        if (!pMulSelRect
            || (pMulSelRect && pMulSelRect.getUseful() == 0)) {
            needStartNewSelRegion = true;
        }

        if (this.m_bIsInMultiProcess && needStartNewSelRegion) {
            this.m_bIsInMultiProcess = false;
        }

        if (!this.m_bIsInMultiProcess) {
            if (needStartNewSelRegion) {
                this.m_pRectSelectService.actLeftMouseDown(tValidPoint);
            }
            this.m_bIsInMultiProcess = true;
        }
        this.actToMultiModify(LGXEnums.LGXMouseMode.LMouseDown, tValidPoint, 1);
        return 0;
    }

    ActLeftMouseUp(point) {
        if (!this.m_bIsInMultiProcess) {
            return 0;
        }
        var ret = 0;
        var tValidPoint = new LXCOM.LGXPoint();
        tValidPoint.clone(point);
        var pMulSelRect = this.dataManger.getMulSelRectGraph();
        this.dataManger.recordRefreshScope(pMulSelRect.getZone());
        var needReport = false;
        if (pMulSelRect && pMulSelRect.getFinish() == 0) {
            this.m_pRectSelectService.actLeftMouseUp(tValidPoint);
            if (this.checkSelResionValid()) {
                var failed = this.analysCurentSel();
                if (failed != 0) {
                    if ((this.dataManger.getMapWorkMode() == LGXEnums.LGXWorkMode.ModifyMode)
                        && (this.dataManger.getMultiModifyMode())
                        && (this.dataManger.getSelectCount() == 0)) {
                        this.dataManger.setMultiModifyMode(false);
                        this.dataManger.clearMultiSelDatas();
                    }
                    return failed;
                }
                else {
                    this.correctSelRegionRect();
                    needReport = true;
                }
            }
            else {
                this.finishMultiMode();
            }
        }
        this.actToMultiModify(LGXEnums.LGXMouseMode.LMouseUp, tValidPoint, 0);
        if (this.dataManger.getSelectCount() == 0) {
            this.finishMultiMode();
            ret = 0;
        }
        else if (needReport) {
            ret = 0x5001;
        }
        this.dataManger.recordRefreshScope(pMulSelRect.getZone());
        return ret;
    }

    actionMouseDoubleClicked(point) {
        var tValidPoint = new LXCOM.LGXPoint();
        tValidPoint.clone(point);
        this.actToMultiModify(LGXEnums.LGXMouseMode.LMouseDbClick, tValidPoint, 0);
        this.finishMultiMode();
        return 0;
    }

    ActMouseMove(point, mosMode) {
        if (this.m_bIsInMultiProcess) {
            var tValidPoint = new LXCOM.LGXPoint();
            tValidPoint.clone(point);
            this.m_pRectSelectService.actMouseMove(tValidPoint);
            this.actToMultiModify(mosMode, tValidPoint, 0);
            if (mosMode == LGXEnums.LGXMouseMode.LMouseDbClick) {
                this.finishMultiMode();
            }
        }
        return 0;
    }

    analysCurentSel() {
        var pMulSelRect = this.dataManger.getMulSelRectGraph();
        if (!pMulSelRect) {
            return 1;
        }
        let failed = 0;
        this.dataManger.clearSelectList();
        this.dataManger.clearBorderList();
        var tSelectList = [];
        var pLayMng = this.dataManger.getLayerManager();
        let selRect = pMulSelRect.getZone();
        let mapViewInfo = this.dataManger.getMapViewInfo();
        if (mapViewInfo.editMode == "autocad"){
            //cad模式下，只要框选区域扫过的图形都算选中
            pLayMng.getGraphIntersectSelRect(selRect, tSelectList);
            failed = this.analysCurentSel_autocad(tSelectList);
        }
        else{
            pLayMng.chkInSelRect(selRect, tSelectList);
            failed = this.analysCurentSel_common(tSelectList);
        }
        return failed;
    }

    analysCurentSel_common(tSelectList) {
        var pMulSelRect = this.dataManger.getMulSelRectGraph();
        tSelectList = this.appendRelateGraph2SelLst(tSelectList);
        var tNodeList = this.processSelGraphs(pMulSelRect, tSelectList);
        var failed = this.processSelNodeAndBoder(tNodeList);
        if (!failed) {
            failed = this.reCorrectBorderLine();
        }
        if (failed != 0) {
            this.dataManger.clearBorderList();
            this.dataManger.clearSelectList();
            this.m_pRectSelectService.releaseSelRect();
        }
        else {
            if (pMulSelRect) {
                var pos = pMulSelRect.getPosCopy();
                if (pos) {
                    this.m_tSelRect.clone(pos.getZone());
                }
            }
            else {
                var tGraphlst = this.dataManger.getSelGraphs();
                this.m_tSelRect.clone(CommonSvc.calGraphsZone(tGraphlst))
            }
        }

        return failed;
    }

    analysCurentSel_autocad(tSelectList) {
        if (tSelectList.length < 2){
            this.dataManger.clearBorderList();
            this.dataManger.clearSelectList();
            this.m_pRectSelectService.releaseSelRect();
            return 1;
        }
        tSelectList.forEach(p => {
            p.setToSelectList();
        });
        var tGraphlst = this.dataManger.getSelGraphs();
        this.m_tSelRect.clone(CommonSvc.calGraphsZone(tGraphlst))
        return 0;
    }

    actToMultiModify(tMode, tPoint, nMouseDown) {
        if ((tMode == LGXEnums.LGXMouseMode.LMouseDbClick) && (this.m_inModifing)) {
            this.dataManger.clearTempData();
            this.m_inModifing = false;
        }

        if (this.dataManger.getSelectCount() == 0) {
            return 0;
        }
        var list = this.dataManger.getSelGraphs();
        var pMulSelRect = this.dataManger.getMulSelRectGraph();
        if (pMulSelRect && list.indexOf(pMulSelRect) == -1) {
            list.push(pMulSelRect);
        }

        var tValidPoint = new LXCOM.LGXPoint();
        tValidPoint.clone(tPoint);

        if (tMode == LGXEnums.LGXMouseMode.mouseMove && nMouseDown == 0) {
            this.calculateMultiModifyKind(tValidPoint, 0);
        }
        else if (tMode == LGXEnums.LGXMouseMode.LMouseDown && !this.m_inModifing) {
            this.calculateMultiModifyKind(tValidPoint, 1);
            this.dataManger.m_pOperStepService.record(1, list);
            this.m_modifyStartPt.clone(tPoint);
            console.log("start drag:");
            console.log(tPoint);
            this.m_inModifing = true;
        }
        else if (tMode == LGXEnums.LGXMouseMode.mouseMove && nMouseDown == 1 && this.m_inModifing) {
            console.log("process drag:");
            console.log(tPoint);
            var nError = this.modifyMultiGraph(tPoint);
            if (nError != 0) {
                return 0;
            }
        }
        else if (tMode == LGXEnums.LGXMouseMode.LMouseUp) {
            var lMosDownUpInSamePos = false;//this.parentControler.chkLMosDwnUpSamePos();
            if (this.m_inModifing) {
                if (!lMosDownUpInSamePos) {
                    this.dataManger.m_pOperStepService.record(0, list);
                }
                else {
                    this.dataManger.m_pOperStepService.removePreStep();
                }
            }
            this.m_inModifing = false;
            var pMulSelRect = this.dataManger.getMulSelRectGraph();
            if (pMulSelRect) {
                pMulSelRect.setModifyCharacter(0);
                pMulSelRect.clearChilds();
                this.dataManger.recordRepaintScope(pMulSelRect);
            }
        }
        return 0;
    }



    modifyMultiGraph(tPoint) {
        var pMulSelRect = this.dataManger.getMulSelRectGraph();
        var nCharacter = 0;
        if (pMulSelRect) {
            nCharacter = pMulSelRect.getModifyCharacter();
        }
        this.dataManger.recordRefreshScope(pMulSelRect.getZone());
        if (nCharacter >= LGXEnums.LGXModGraphKind.CommonStSelKind) {
            console.log("modMultiByControlGraph ****************");
            this.modMultiByControlGraph(tPoint, nCharacter);
        }
        else {
            console.log("translateMultiGraph ****************");
            this.translateMultiGraph(tPoint);
        }

        if (pMulSelRect) {
            this.dataManger.recordRefreshScope(pMulSelRect.getZone());
        }

        return 0;
    }

    calculateMultiModifyKind(tPoint) {
        var scaling = this.dataManger.getScaling();
        var pMulSelRect = this.dataManger.getMulSelRectGraph();
        if (!pMulSelRect) {
            return 0;
        }
        var nCharacter = this.getMulModifyCharater(tPoint, pMulSelRect, scaling);
        pMulSelRect.setModifyCharacter(nCharacter);
        var offset = globalconsts.SelectGap / scaling;
        var frameRect = new LXCOM.LGXRect();
        frameRect.clone(pMulSelRect.getZone());
        frameRect.expand(offset);
        this.dataManger.recordRefreshScope(frameRect);
        return nCharacter;
    }

    modMultiByControlGraph(tPoint, nCharacter) {
        var pMulSelRect = this.dataManger.getMulSelRectGraph();
        if (!pMulSelRect) {
            return 1;
        }
        pMulSelRect.setSelKind(nCharacter);

        var scaling = this.dataManger.getScaling();
        var nGap1 = tPoint.x - this.m_modifyStartPt.x;
        var nGap2 = tPoint.y - this.m_modifyStartPt.y;
        if ((Math.abs(nGap1 * scaling) < 1) && (Math.abs(nGap2 * scaling) < 1)) {
            console.log("none offset --------------------");
            return 0;
        }

        if (pMulSelRect.m_tChildGraphLst.length == 0) {
            var nCount = this.dataManger.getSelectCount();
            for (let i = 0; i < nCount; i++) {
                var pGraph = this.dataManger.getGraphInSelectList(i);
                pMulSelRect.addChild(pGraph);
            }
        }
        var tGap = { x: nGap1, y: nGap2 };
        //缩放后，设备与线路会被拉开，要重新把坐标点做到对齐
        // this.resetLineConn2Dev(tScaleLineEnd2NodeInfoLst);
        var cmdinfo = new LXCOM.LXModifyCMDInfo();
        cmdinfo.mapscale = this.dataManger.getMapScale();
        cmdinfo.scaling = this.dataManger.getScaling();
        let succes = pMulSelRect.modifyByOffset(tGap, cmdinfo);
        if (succes) {
            this.m_modifyStartPt.clone(tPoint);
        }
        else {
            console.log("succes=" + succes);
        }
        return 0;
    }

    checkSelResionValid() {
        var scaling = this.dataManger.getScaling();
        var nInValidSel = true;
        var pRegionPos = this.dataManger.getSelRectPosition();
        if (pRegionPos) {
            var selRect = pRegionPos.getZone();
            var nSelRecWid = selRect.width() * scaling;
            var nSelRecHgt = selRect.height() * scaling;
            if (Math.abs(nSelRecWid) <= 15 || Math.abs(nSelRecHgt) <= 15) {
                nInValidSel = false;
            }
        }
        return nInValidSel;
    }

    translateMultiGraph(tPoint) {
        var nCount = this.dataManger.getSelectCount();
        if (nCount < 1) {
            return -1;
        }

        var detax = tPoint.x - this.m_modifyStartPt.x;
        var detay = tPoint.y - this.m_modifyStartPt.y;
        if (Math.abs(detax) < globalconsts.ZERO_8E && Math.abs(detay) < globalconsts.ZERO_8E) {
            return 0;
        }
        if (detax > 100 || detay > 100) {
            detax = 0;
            detay = 0;
        }
        var pMulSelRect = this.dataManger.getMulSelRectGraph();
        var svc = new multiTransSvc(this.dataManger, null);
        var origOffset = new LXCOM.LGXPoint();
        origOffset.x = detax;
        origOffset.y = detay;
        var validOffset = new LXCOM.LGXPoint();
        var rst = svc.translateMultiGraphs(pMulSelRect, origOffset, validOffset);
        this.m_modifyStartPt.x += validOffset.x;
        this.m_modifyStartPt.y += validOffset.y;
        return rst;
    }



    getMulModifyCharater(tPoint, pMulSelRect, nScaling) {
        var point = new LXCOM.LGXPoint();
        point.clone(tPoint);
        var kind = pMulSelRect.calculateSelKind(point, nScaling, this.dataManger.getMapScale(), false);
        return kind;
    }


    prepareToMultiMove(tPoint) {
        //this.m_pOperStepService.RecordMultiInformation(1, tPoint);
        this.m_modifyStartPt.clone(tPoint);
        this.m_inModifing = true;
    }

    classifyMultiSelGraphs(multiSelGraphLst, borderLst, modifyLst) {
        for (let i = 0; i < multiSelGraphLst.size(); i++) {
            var p = multiSelGraphLst[i];
            if (checkInBorder(p, multiSelGraphLst)) {
                if (borderLst.indexOf(p) == -1) {
                    borderLst.push(p);
                }
            }
            else {
                if (modifyLst.indexOf(p) == -1) {
                    modifyLst.push(p);
                }
            }
        }
    }

    keyMoveGraph(offset) {
        var pMulSelRect = this.dataManger.getMulSelRectGraph();
        var svc = new CMultiModifySvc(m_pDataManager, m_pOperStepService);
        var validOffset = new LXCOM.LGXPoint();
        var rst = svc.translateMultiGraphs(pMulSelRect, offset, validOffset);
        return rst;
    }


    checkInBorder(pGraph, multiSelGraphLst) {
        var flag = false;
        return flag;
    }

    clearMem() {
        this.m_inModifing = false;
        this.m_bIsInMultiProcess = false;
    }

    finishPaste() {
        this.m_bIsInMultiProcess = true;
    }

    processBorderGraph(pGraph, tSelectList, resConnNdLst, tOutNodeList) {
        var scaling = this.dataManger.getScaling();
        var mapscale = this.dataManger.getMapScale();
        var pRefBusGraph = null;
        for (let i = 0; i < resConnNdLst.length; i++) {
            var tempNode = resConnNdLst[i];
            if (tempNode.getRefRes()) {
                var pRefGraph = tempNode.getRefRes().getRefGraph();
                if (pRefGraph.m_graphType == CommBusGraph_type) {
                    pRefBusGraph = pRefGraph;
                }
                else {
                    if (tOutNodeList.indexOf(tempNode) == -1) {
                        tOutNodeList.push(tempNode);
                    }
                }
            }
            else {
                if (tOutNodeList.indexOf(tempNode) == -1) {
                    tOutNodeList.push(tempNode);
                }
            }
        }

        if (!pRefBusGraph) {
            //设备关联的节点都不属于母线，则直接放批量修改队列中
            pGraph.setToSelectList();
        }
        else {
            //线路两端的节点之一如果属于母线，则要判断该母线是否也在框选区域内，
            //如果不在，则要把本线路做为边界设备处理
            if (tSelectList.indexOf(pRefBusGraph) != -1) {
                pGraph.setToSelectList();
            }
            else {
                var connPt = new LXCOM.LGXPoint();
                var nCntConn = 0;//CBaseService:: getTwoGraphSameConnKind(scaling, mapscale, pGraph, pRefBusGraph, connPt);
                if (nCntConn > 0) {
                    this.dataManger.add2BordeList(pGraph);
                    var pLnPos = pGraph.getPosCopy();
                    var poscount = pLnPos.posList.size();
                    var otherEndIdx = poscount;
                    if (nCntConn == poscount) {
                        otherEndIdx = 1;
                    }
                    var pOtherPt = pLnPos.posList[otherEndIdx - 1];
                    pGraph.setSelectRefPos(pOtherPt);
                    pGraph.setSelKind(otherEndIdx);
                }
            }
        }
        return 0;
    }

    finishMultiMode() {
        var pMulSelRect = this.dataManger.getMulSelRectGraph();
        if (pMulSelRect) {
            this.dataManger.recordRepaintScope(pMulSelRect);
        }
        this.m_pRectSelectService.releaseSelRect();
        this.m_bIsInMultiProcess = false;
        this.m_inModifing = false;
        this.dataManger.setMultiModifyMode(false);
        this.dataManger.clearSelectList();
        this.dataManger.clearBorderList();
    }

    correctSelRegionRect() {
        var pMulSelRect = this.dataManger.getMulSelRectGraph();
        if (pMulSelRect) {
            this.dataManger.recordRepaintScope(pMulSelRect);
            var tSelGraphLst = this.dataManger.getSelGraphs();
            var rect = CommonSvc.calGraphsZone(tSelGraphLst);
            var multiPos = new LXCOORD.MultiPos();
            multiPos.addPoint(rect.ltPt());
            multiPos.addPoint(rect.rtPt());
            multiPos.addPoint(rect.rbPt());
            multiPos.addPoint(rect.lbPt());
            pMulSelRect.setPos(multiPos);
            this.dataManger.recordRepaintScope(pMulSelRect);
        }
    }

    appendRelateGraph2SelLst(tOrignSelLst) {
        var tmpSelLst = tOrignSelLst;
        // for (let i = 0; i < tOrignSelLst.lenth; i++) {
        //     var p = tOrignSelLst[i];
        //     var pSup = p.getMemberOfContainer();
        //     if (pSup) {
        //         add2GraphLst(pSup, tmpSelLst);
        //         var childLst = pSup.getChildList();
        //         for (let m = 0; m < childLst.lenth; m++) {
        //             var pChild = childLst[m];
        //             add2GraphLst(pChild, tmpSelLst);
        //             var pLabel = pChild.getLabelGraph(1);
        //             if (pLabel) {
        //                 add2GraphLst(pLabel, tmpSelLst);
        //             }
        //         }
        //     }
        // }
        return tmpSelLst;
    }

    processSelGraphs(pSelRegion, tSelList) {
        var tNodeList = new Array();
        for (var idx in tSelList) {
            var pGraph = tSelList[idx];
            if (pGraph.m_graphType == LGXEnums.LGXGraphType.LineGraph_type) {
                this.processSelLine(pSelRegion, pGraph, tNodeList, tSelList);
            }
            else {
                var pResource = pGraph.m_topoRes;
                if (pResource) {
                    var tResConnNdLst = pResource.getConnNodeList();
                    for (var ndidx in tResConnNdLst) {
                        var pNode = tResConnNdLst[ndidx];
                        this.add2NodeLst(pNode, tNodeList);
                    }
                }
                pGraph.setToSelectList();
            }
        }
        return tNodeList;
    }

    processSelLine(pSelRegion, pLineGraph, tNodeList, tSelList) {
        if (!this.chkLnTwoEndInRect(pLineGraph, pSelRegion.getZone())) {
            return;
        }

        //对于线路，被选进框选区域后，需要确认其两端节点都进入了框选区域，如果某端节点关联
        //了设备（开关、刀闸等非母线设备），则要检测该设备是否也被选了进来，如果没有则本线路
        //要作为边界设备处理，不能整体移动，
        //否则会导致线路和设备的连接断开（图形效果上断开，拓扑上仍然是连接的）
        var isBorderLnGraph = false;
        var pResource = pLineGraph.m_topoRes;
        if (pResource) {
            var tResConnNdLst = pResource.getConnNodeList();
            for (let m = 0; m < tResConnNdLst.length; m++) {
                var pNode = tResConnNdLst[m];
                var pNdRes = pNode.getRefRes();
                if (pNdRes) {
                    var pNdResRefGraph = pNdRes.getRefGraph();
                    if (pNdResRefGraph) {
                        if (pNdResRefGraph.m_graphType != LGXEnums.LGXGraphType.CommBusGraph_type) {
                            if (tSelList.indexOf(pNdResRefGraph) == -1) {
                                isBorderLnGraph = true;
                            }
                            else {
                                this.add2NodeLst(pNode, tNodeList);
                            }
                        }
                        else {
                            this.add2NodeLst(pNode, tNodeList);
                        }
                    }
                }
                else {
                    this.add2NodeLst(pNode, tNodeList);
                }
            }
        }

        if (!isBorderLnGraph) {
            pLineGraph.setToSelectList();
        }
        return;
    }

    processSelNodeAndBoder(tNodeList) {
        var failed = 0;
        var scaling = this.dataManger.getScaling();
        var mapscale = this.dataManger.getMapScale();
        var pResMng = this.dataManger.getTopoManager();
        //pResMng.clearConnect();
        var nNode = tNodeList.lenth;
        for (let i = 0; i < nNode && failed == 0; i++) {
            var pNode = tNodeList[i];
            if (pResMng.inModifyNode(pNode) != -1) {
                continue;
            }

            pNode.setRefPos(pNode.getx(), pNode.gety());
            pResMng.addModifyNode(pNode);

            var nCntConn = 0;
            var pCntLnSeg = null;
            var pCntGraph = null;
            var nLineCount = pNode.getConnLineCount();
            for (let n = 0; n < nLineCount && failed == 0; n++) {
                pCntLnSeg = pNode.getConnLine(n);
                pCntGraph = pCntLnSeg.getRefGraph();
                if (pCntGraph == null) {
                    continue;
                }

                if (pCntGraph.getInSelScope() == 0) {
                    failed = 1;
                    break;
                }

                if (this.dataManger.getIndexInSelectList(pCntGraph) != -1) {
                    continue;
                }
                if (this.dataManger.getIndexInBorderList(pCntGraph) != -1) {
                    continue;
                }

                var otherGraph = null;
                if (pNode.getRefRes() != null) {
                    otherGraph = pNode.getRefRes().getRefGraph();
                }
                else {
                    if (nLineCount > 1) {
                        var otherIndex = 0;
                        for (let h = 0; h < nLineCount; h++) {
                            if (h != n) {
                                otherIndex = h;
                                break;
                            }
                        }

                        var pOtherLnSeg = pNode.getConnLine(otherIndex);
                        if (pOtherLnSeg != null && pCntLnSeg != pOtherLnSeg) {
                            otherGraph = pOtherLnSeg.getRefGraph();
                        }
                    }
                    else if (utils.isMswEqp(pNode.getSuperiorID())) {
                        var mswRes = this.dataManger.findResource(pNode.getSuperiorID());
                        otherGraph = this.dataManger.findGraph(mswRes.m_nGraphicID);
                    }
                }

                if (otherGraph) {
                    var connPt = LXCOM.LGXPoint();
                    nCntConn = 0;//CBaseService::getTwoGraphSameConnKind(scaling, mapscale,pCntGraph, otherGraph, connPt);
                    if (nCntConn > 0) {
                        this.dataManger.add2BordeList(pCntGraph);
                        pCntGraph.setSelectRefPos(pNode.getPos());
                        pCntGraph.setSelKind(nCntConn);
                    }
                    else {
                        failed = 1;
                    }
                }
            }
        }
        return failed;
    }

    reCorrectBorderLine() {
        return 0;
    }

    add2GraphLst(pGraph, list) {
        if (list.indexOf(pGraph) == -1) {
            list.push(pGraph);
        }
    }
    add2NodeLst(pNode, tNodeList) {
        if (tNodeList.indexOf(pNode) == -1) {
            tNodeList.push(pNode);
        }
    }


    getMayConnGraphs(chkRect) {

    }

    updateSelRect(character, pFixPoint, nWidRatio, nHghRatio) {
        var nGapX = 0;
        var nGapY = 0;
        switch (character) {
            case 1:
                nGapX = Math.abs(this.m_tSelRect.left - pFixPoint.x) * nWidRatio;
                nGapY = Math.abs(this.m_tSelRect.top - pFixPoint.y) * nHghRatio;
                this.m_tSelRect.left += nGapX;
                this.m_tSelRect.top += nGapY;
                break;

            case 2:
                nGapX = Math.abs(this.m_tSelRect.right - pFixPoint.x) * nWidRatio;
                nGapY = Math.abs(this.m_tSelRect.top - pFixPoint.y) * nHghRatio;
                this.m_tSelRect.right += nGapX;
                this.m_tSelRect.top += nGapY;
                break;

            case 3:
                nGapX = Math.abs(this.m_tSelRect.right - pFixPoint.x) * nWidRatio;
                nGapY = Math.abs(this.m_tSelRect.bottom - pFixPoint.y) * nHghRatio;
                this.m_tSelRect.right += nGapX;
                this.m_tSelRect.bottom += nGapY;
                break;

            case 4:
                var nGapX = Math.abs(this.m_tSelRect.left - pFixPoint.x) * nWidRatio;
                var nGapY = Math.abs(this.m_tSelRect.bottom - pFixPoint.y) * nHghRatio;
                this.m_tSelRect.left += nGapX;
                this.m_tSelRect.bottom += nGapY;
                break;
        }
    }


    //先记录好缩放前线路端点和拓扑点的坐标对应关系
    recordScaleLineDev(tInfoLst) {
        var tLineLst = new Array();
        var nCount = this.dataManger.getSelectCount();
        for (let i = 0; i < nCount; i++) {
            var pGraph = this.dataManger.getGraphInSelectList(i);
            if (pGraph.m_graphType == LGXEnums.LGXGraphType.LineGraph_type) {
                tLineLst.push(pGraph);
            }
        }

        nCount = this.dataManger.getBorderCount();
        for (let i = 0; i < nCount; i++) {
            var pGraph = this.dataManger.getGraphInBorderList(i);
            if (pGraph.m_graphType == LGXEnums.LGXGraphType.LineGraph_type) {
                tLineLst.push(pGraph);
            }
        }
        this.recordScaleLineDes(tLineLst, tInfoLst);
    }

    recordScaleLineDevs(tLineLst, tInfoLst) {
        for (let i = 0; i < tLineLst.size(); i++) {
            var pLine = tLineLst[i];
            if (pLine.m_topoRes) {
                this.recordScaleSingleLineDev(pLine, tInfoLst);
            }
        }
    }

    recordScaleSingleLineDev(pGraph, tInfoLst) {
        var pLinePos = pGraph.getPosCopy();
        var pHeadPt = pLinePos.getHead();
        var pTailPt = pLinePos.getTail();
        var pLineSeg = pGraph.m_topoRes;
        var nodeLst = pLineSeg.getConnNodeList();
        if (nodeLst.size() < 1) {
            return;
        }

        var pLineGraph = pGraph;
        var pHeadNode = pLineGraph.getNodeInLineEndPos(pHeadPt);
        var pTailNode = pLineGraph.getNodeInLineEndPos(pTailPt);

        var tInfo = new TScaleLineEnd2NodeInfo(pGraph);
        if (pHeadNode) {
            tInfo.pHeadEndNode = pHeadNode;
            tInfo.headPt = pHeadPt;
        }

        if (pTailNode) {
            tInfo.pTailEndNode = pTailNode;
            tInfo.tailPt = pTailPt;
        }
        tInfoLst.push(tInfo);
    }

    resetLineConn2Dev(tInfoLst) {
        var mapscale = this.dataManger.getMapScale();
        for (let i = 0; i < tInfoLst.length; i++) {
            var t = tInfoLst[i];
            var pGraph = t.pLineGraph;
            var pLinePos = pGraph.getPosCopy();
            var pHeadPt = pLinePos.getHead();
            if (t.pHeadEndNode) {
                pHeadPt = t.pHeadEndNode.getPos();
            }
            var pTailPt = pLinePos.getTail();
            if (t.pTailEndNode) {
                pTailPt = t.pTailEndNode.getPos();
            }
            this.dataManger.recordRepaintScope(pGraph);
            pGraph.SetPos(box.pos);
            pGraph.GetScope(mapscale);
            this.dataManger.recordRepaintScope(pGraph);
        }

    }

    chkLnTwoEndInRect(pGraph, rect) {
        var linePos = pGraph.getPos();
        for (let i = 0; i < linePos.posList.length; i++) {
            var pt = linePos.posList[i];
            if (!rect.ptInRect(pt)) {
                return false;
            }
        }
        return true;
    }

}

export default { MultiModifyControler }

